Skip to content

Add dashed line support to BufferPolylineMaterial - #1

Open
DanielLeone wants to merge 1 commit into
mainfrom
buffer-polyline-dashed-material_Daniel-Leone
Open

Add dashed line support to BufferPolylineMaterial#1
DanielLeone wants to merge 1 commit into
mainfrom
buffer-polyline-dashed-material_Daniel-Leone

Conversation

@DanielLeone

Copy link
Copy Markdown

Adds dashes to BufferPolylineMaterial. Ticket:
FTP-16167. Targets this fork's main
not proposed upstream.

The API

Property Default Meaning
gapColor Color.TRANSPARENT drawn in the gaps; transparent discards, so gaps are holes
dashRepeat 1 pattern cycles along the whole line, 0–255
dashOffset 0 phase within a cycle, 0–1
dashPattern 65535 (0xFFFF) 16-bit on/off bitmask sampled within each cycle

Defaults are fully solid, so existing polylines are untouched.

How it works

The material layout grows 12 bytes (GAP_COLOR_U32, DASH_REPEAT_U8,
DASH_OFFSET_U8, DASH_PATTERN_U16) with matching pack/unpack, and the values
reach the shaders through a new dashParams vec4 vertex attribute carrying
(encodedGapColorRGB8, gapAlpha, dashRepeat + dashOffset, dashPattern). The integer
cycle count and the fractional phase share one float; the shader splits them with
floor()/fract(). dashOffset is stored in 256ths so a quarter turn round-trips
exactly.

The fragment shader walks the pattern along texCoord (0..1 down the line) rather
than gl_FragCoord, so dashes are anchored to the geometry: bands stay put on
the line as the camera pans, and scale with the line as it zooms, instead of
crawling in screen space. That's the main design choice here and it's the opposite
of upstream's PolylineDashMaterialProperty, which is sized in screen pixels.

Checked

  • eslint, prettier and tsc (the material file is // @ts-check) via the repo hooks
  • wireless-manager-front-end builds and bundles clean with this branch linked in
    (bun run build, exit 0, no new warnings)

Not checked yet

  • visual output — no screenshots of actual dashed lines yet
  • cesium's own specs for the buffer-polyline path
  • cost of the extra per-vertex vec4 on large collections, which is the thing most
    worth measuring before this goes near a customer site

Note on consuming it

Only main publishes to our registry, so the front-end can't pick this up as
@ftpsolutions/cesium@… until it merges. Until then, use bun run cesium:link in
the front-end against this branch.

🤖 Generated with Claude Code

Four new material properties - gapColor, dashRepeat, dashOffset and dashPattern -
packed into 12 more bytes of the material layout (gap colour as U32, repeat and
offset as U8 each, the pattern as U16) and carried to the shaders in a new
dashParams vec4 vertex attribute.

The pattern is a 16-bit on/off bitmask sampled within each cycle: 1 draws colour,
0 draws gapColor, and the default 0xFFFF is fully solid, so existing polylines are
unaffected. A transparent gapColor discards, so gaps read as empty space.

Dashes are anchored to the geometry rather than to the screen: the fragment shader
walks the pattern along texCoord (0..1 down the line) instead of gl_FragCoord, so
bands stay put on the line as the camera pans and scale with it as it zooms.
dashOffset phase-shifts the pattern within a cycle, stored in 256ths so a quarter
turn round-trips exactly.

FTP-16167.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant